export const debounce = {
  inserted(el, binding) {
    let timer = null;
    el.addEventListener('click', () => {
      if (timer) {
        clearTimeout(timer);
        timer = null;
      }
      timer = setTimeout(() => {
        binding.value();
      }, binding.arg || 500);
    });
  }
};

export const debounceImmediate = {
  inserted(el, binding) {
    let timer = null;
    let flag = true;
    el.addEventListener('click', () => {
      if (timer) {
        clearTimeout(timer);
        timer = null;
      }
      if (flag) {
        binding.value();
        flag = false;
      }
      timer = setTimeout(() => {
        flag = true;
      }, binding.arg ? Number(binding.arg) : 500);
    });
  }
};
